package com.huayi.datagovernance.device;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huayi.datagovernance.common.SysConstant;
import com.huayi.datagovernance.dao.master.DeviceDao;
import com.huayi.datagovernance.dao.master.MasterUserMapper;
import com.huayi.datagovernance.dao.slave.LxTaskDao;
import com.huayi.datagovernance.entity.ConfModelmeta;
import com.huayi.datagovernance.entity.TYwTaskYk;
import com.huayi.datagovernance.entity.TzyAppList;
import com.huayi.datagovernance.service.ConfModelmetaService;
import com.huayi.datagovernance.service.TYwTaskYkService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 模型服务 接口测试
 * @author wuch
 * @version 1.0
 * @date 2021/4/22 12:08
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class DeviceApiDemo {
    @Resource
    private DeviceDao deviceDao;

    @Resource
    private ConfModelmetaService modelmetaService;

    @Resource
    private MasterUserMapper masterUserMapper;

    @Resource
    private LxTaskDao lxTaskDao;

    @Resource
    private TYwTaskYkService taskYkService;

    @Test
    public void test1(){
        String sswlg = "8144768";
        String modelnamewlg = SysConstant.MODELNAME_WLGT;
        JSONObject wlgInfo = deviceDao.getSbmcByModelnameAndOid(StrUtil.strBuilder(SysConstant.PREFIX_TABLE_ZY, modelnamewlg, SysConstant.SUFFIX_TABLE_VER).toString()
                , Long.valueOf(sswlg));
        String sbmc = StrUtil.emptyToDefault(wlgInfo.getString("sbmc"), "");
        Console.log(sbmc);
    }

    @Test
    public void test2(){
        QueryWrapper<ConfModelmeta> wrapper = new QueryWrapper<>();
//        wrapper.eq(SysConstant.FIELD_MODELID, Long.valueOf("14000000"));
        wrapper.apply(SysConstant.FIELD_MODELID+" = {0}", Long.valueOf("14000000"));
//        Map<String, Object> map = modelmetaService.getMap(wrapper);
//        ConfModelmeta one = modelmetaService.getOne(wrapper);
//        Console.log(one);
        QueryWrapper<Map<String,Object>> wrapper2 = new QueryWrapper<>();
        wrapper2.apply("A."+SysConstant.FIELD_MODELID+" = {0}", Long.valueOf("14000000"));
        List<JSONObject> jsonObjects = masterUserMapper.selectModelMeta(wrapper2);
        Console.log(jsonObjects);
    }

    @Test
    public void test3(){
        QueryWrapper<ConfModelmeta> wrapper = new QueryWrapper<>();
        String column ="t.oid,t.wtname,t.sbname,t.sbzlx,t.sboid,t.sbid,st_astext(t.shape) AS shape,t.state,t.tqsbid,t.yxdw,t.yxdwmc,t.gdoid,a.modelalias";
        wrapper.select(column);
//        ConfModelmeta one = modelmetaService.getOne(wrapper);

    }

    /**
     * 朗新oracle库操作示例
     */
    @Test
    public void test4(){
        List<TzyAppList> tzyAppList = lxTaskDao.getTzyAppList();
        System.out.println(tzyAppList);
        TzyAppList tzyApp = tzyAppList.get(0);
        TYwTaskYk tYwTaskYk = new TYwTaskYk();
        tYwTaskYk.setSchemaId(tzyApp.getEquipRelas().get(0).getSchemaId())
                .setTaskid(tzyApp.getAppNo())
                .setSbmc(tzyApp.getEquipRelas().get(0).getTranName())
                .setTqId(tzyApp.getEquipRelas().get(0).getTgId());
        taskYkService.save(tYwTaskYk);

    }
}
